/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;

/**
 *
 * @author yaqiang
 */
public class frmMain extends javax.swing.JFrame {

    /**
     * Creates new form frmMain
     */
    public frmMain() {
        initComponents();
        
        this.setTitle("wContour Demo");
        this.jLabel_StartColor.setBackground(Color.yellow);
        this.jLabel_EndColor.setBackground(Color.red);
        this.jCheckBox_ContourPolygon.setSelected(true);
        this.jTextField_Highlight.setEnabled(false);
        this.drawingPanel1.setDrawContourPolygon(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jCheckBox_DiscreteData = new javax.swing.JCheckBox();
        jCheckBox_Clipped = new javax.swing.JCheckBox();
        jCheckBox_GridData = new javax.swing.JCheckBox();
        jCheckBox_AntiAlias = new javax.swing.JCheckBox();
        jCheckBox_BorderLine = new javax.swing.JCheckBox();
        jCheckBox_Highlight = new javax.swing.JCheckBox();
        jCheckBox_ContourLine = new javax.swing.JCheckBox();
        jCheckBox_ContourPolygon = new javax.swing.JCheckBox();
        jTextField_Highlight = new javax.swing.JTextField();
        jLabel_StartColor = new javax.swing.JLabel();
        jLabel_EndColor = new javax.swing.JLabel();
        drawingPanel1 = new DrawingPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu_Sample = new javax.swing.JMenu();
        jMenuItem_RandomData = new javax.swing.JMenuItem();
        jMenu_Interpolation = new javax.swing.JMenu();
        jMenuItem_IDW_Neighbour = new javax.swing.JMenuItem();
        jMenuItem_IDW_Radius = new javax.swing.JMenuItem();
        jMenuItem_Cressman = new javax.swing.JMenuItem();
        jMenuItem_Streamline = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem_Test = new javax.swing.JMenuItem();
        jMenu_Edit = new javax.swing.JMenu();
        jMenuItem_OutputData = new javax.swing.JMenuItem();
        jMenu_Help = new javax.swing.JMenu();
        jMenuItem_About = new javax.swing.JMenuItem();
        jMenuItem_Help = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jCheckBox_DiscreteData.setText("Discreate Data");
        jCheckBox_DiscreteData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_DiscreteDataActionPerformed(evt);
            }
        });

        jCheckBox_Clipped.setText("Clipped");
        jCheckBox_Clipped.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_ClippedActionPerformed(evt);
            }
        });

        jCheckBox_GridData.setText("Grid Data");
        jCheckBox_GridData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_GridDataActionPerformed(evt);
            }
        });

        jCheckBox_AntiAlias.setText("AntiAlias");
        jCheckBox_AntiAlias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_AntiAliasActionPerformed(evt);
            }
        });

        jCheckBox_BorderLine.setText("BorderLine");
        jCheckBox_BorderLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_BorderLineActionPerformed(evt);
            }
        });

        jCheckBox_Highlight.setText("Highlight");
        jCheckBox_Highlight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_HighlightActionPerformed(evt);
            }
        });

        jCheckBox_ContourLine.setText("ContourLine");
        jCheckBox_ContourLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_ContourLineActionPerformed(evt);
            }
        });

        jCheckBox_ContourPolygon.setText("ContourPolygon");
        jCheckBox_ContourPolygon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_ContourPolygonActionPerformed(evt);
            }
        });

        jTextField_Highlight.setText("0");
        jTextField_Highlight.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField_HighlightKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox_DiscreteData)
                    .addComponent(jCheckBox_Clipped))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox_AntiAlias)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox_Highlight)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_Highlight, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox_GridData)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox_BorderLine)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox_ContourLine)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBox_ContourPolygon)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox_DiscreteData)
                    .addComponent(jCheckBox_GridData)
                    .addComponent(jCheckBox_BorderLine)
                    .addComponent(jCheckBox_ContourLine)
                    .addComponent(jCheckBox_ContourPolygon))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox_Clipped)
                    .addComponent(jCheckBox_AntiAlias)
                    .addComponent(jCheckBox_Highlight)
                    .addComponent(jTextField_Highlight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel_StartColor.setBackground(new java.awt.Color(255, 255, 204));
        jLabel_StartColor.setText("Start Color");
        jLabel_StartColor.setOpaque(true);
        jLabel_StartColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel_StartColorMouseClicked(evt);
            }
        });

        jLabel_EndColor.setBackground(new java.awt.Color(255, 51, 0));
        jLabel_EndColor.setText("End Color");
        jLabel_EndColor.setOpaque(true);
        jLabel_EndColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel_EndColorMouseClicked(evt);
            }
        });

        drawingPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                drawingPanel1ComponentResized(evt);
            }
        });

        javax.swing.GroupLayout drawingPanel1Layout = new javax.swing.GroupLayout(drawingPanel1);
        drawingPanel1.setLayout(drawingPanel1Layout);
        drawingPanel1Layout.setHorizontalGroup(
            drawingPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 749, Short.MAX_VALUE)
        );
        drawingPanel1Layout.setVerticalGroup(
            drawingPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 383, Short.MAX_VALUE)
        );

        jMenu_Sample.setText("Sample");

        jMenuItem_RandomData.setText("Random Data");
        jMenuItem_RandomData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_RandomDataActionPerformed(evt);
            }
        });
        jMenu_Sample.add(jMenuItem_RandomData);

        jMenu_Interpolation.setText("Interpolation");

        jMenuItem_IDW_Neighbour.setText("IDW_Neighbour");
        jMenuItem_IDW_Neighbour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_IDW_NeighbourActionPerformed(evt);
            }
        });
        jMenu_Interpolation.add(jMenuItem_IDW_Neighbour);

        jMenuItem_IDW_Radius.setText("IDW_Radius");
        jMenuItem_IDW_Radius.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_IDW_RadiusActionPerformed(evt);
            }
        });
        jMenu_Interpolation.add(jMenuItem_IDW_Radius);

        jMenuItem_Cressman.setText("Cressman");
        jMenuItem_Cressman.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_CressmanActionPerformed(evt);
            }
        });
        jMenu_Interpolation.add(jMenuItem_Cressman);

        jMenu_Sample.add(jMenu_Interpolation);

        jMenuItem_Streamline.setText("Streamline");
        jMenuItem_Streamline.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_StreamlineActionPerformed(evt);
            }
        });
        jMenu_Sample.add(jMenuItem_Streamline);
        jMenu_Sample.add(jSeparator1);

        jMenuItem_Test.setText("Test");
        jMenuItem_Test.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_TestActionPerformed(evt);
            }
        });
        jMenu_Sample.add(jMenuItem_Test);

        jMenuBar1.add(jMenu_Sample);

        jMenu_Edit.setText("Edit");

        jMenuItem_OutputData.setText("Output Data");
        jMenuItem_OutputData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_OutputDataActionPerformed(evt);
            }
        });
        jMenu_Edit.add(jMenuItem_OutputData);

        jMenuBar1.add(jMenu_Edit);

        jMenu_Help.setText("Help");

        jMenuItem_About.setText("About");
        jMenuItem_About.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_AboutActionPerformed(evt);
            }
        });
        jMenu_Help.add(jMenuItem_About);

        jMenuItem_Help.setText("Help");
        jMenuItem_Help.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_HelpActionPerformed(evt);
            }
        });
        jMenu_Help.add(jMenuItem_Help);

        jMenuBar1.add(jMenu_Help);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel_StartColor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel_EndColor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(76, Short.MAX_VALUE))
            .addComponent(drawingPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel_StartColor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel_EndColor))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(drawingPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem_RandomDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_RandomDataActionPerformed
        // TODO add your handling code here:
        digRandomData aFrm = new digRandomData(this, false);
        //aFrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //aFrm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        aFrm.setLocationRelativeTo(this);
        aFrm.setVisible(true);
    }//GEN-LAST:event_jMenuItem_RandomDataActionPerformed

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        
    }//GEN-LAST:event_formComponentResized

    private void drawingPanel1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_drawingPanel1ComponentResized
        // TODO add your handling code here:
        this.drawingPanel1.setScale();
    }//GEN-LAST:event_drawingPanel1ComponentResized

    private void jCheckBox_DiscreteDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_DiscreteDataActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawDiscreteData(this.jCheckBox_DiscreteData.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_DiscreteDataActionPerformed

    private void jCheckBox_GridDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_GridDataActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawGridData(this.jCheckBox_GridData.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_GridDataActionPerformed

    private void jCheckBox_BorderLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_BorderLineActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawBorderLine(this.jCheckBox_BorderLine.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_BorderLineActionPerformed

    private void jCheckBox_ContourLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_ContourLineActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawContourLine(this.jCheckBox_ContourLine.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_ContourLineActionPerformed

    private void jCheckBox_ContourPolygonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_ContourPolygonActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawContourPolygon(this.jCheckBox_ContourPolygon.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_ContourPolygonActionPerformed

    private void jCheckBox_ClippedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_ClippedActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setDrawClipped(this.jCheckBox_Clipped.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_ClippedActionPerformed

    private void jCheckBox_AntiAliasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_AntiAliasActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setAntiAlias(this.jCheckBox_AntiAlias.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_AntiAliasActionPerformed

    private void jCheckBox_HighlightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_HighlightActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.setHighlight(this.jCheckBox_Highlight.isSelected());
        this.jTextField_Highlight.setEnabled(this.jCheckBox_Highlight.isSelected());
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jCheckBox_HighlightActionPerformed

    private void jTextField_HighlightKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField_HighlightKeyPressed
        // TODO add your handling code here:
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.drawingPanel1.setHighlightIdx(Integer.parseInt(this.jTextField_Highlight.getText()));
            this.drawingPanel1.repaint();
        }
    }//GEN-LAST:event_jTextField_HighlightKeyPressed

    private void jLabel_StartColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_StartColorMouseClicked
        // TODO add your handling code here:
        Color aColor = JColorChooser.showDialog(rootPane, null, this.jLabel_StartColor.getBackground());
        this.jLabel_StartColor.setBackground(aColor);
        this.drawingPanel1.setStartColor(aColor);
        this.drawingPanel1.createColors();
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jLabel_StartColorMouseClicked

    private void jLabel_EndColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_EndColorMouseClicked
        // TODO add your handling code here:
        Color aColor = JColorChooser.showDialog(rootPane, null, this.jLabel_EndColor.getBackground());
        this.jLabel_EndColor.setBackground(aColor);
        this.drawingPanel1.setEndColor(aColor);
        this.drawingPanel1.createColors();
        this.drawingPanel1.repaint();
    }//GEN-LAST:event_jLabel_EndColorMouseClicked

    private void jMenuItem_IDW_NeighbourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_IDW_NeighbourActionPerformed
        // TODO add your handling code here:
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        this.drawingPanel1.sample_Interpolate(1);
        this.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_jMenuItem_IDW_NeighbourActionPerformed

    private void jMenuItem_IDW_RadiusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_IDW_RadiusActionPerformed
        // TODO add your handling code here:
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        this.drawingPanel1.sample_Interpolate(2);
        this.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_jMenuItem_IDW_RadiusActionPerformed

    private void jMenuItem_CressmanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_CressmanActionPerformed
        // TODO add your handling code here:
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        this.drawingPanel1.sample_Interpolate(3);
        this.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_jMenuItem_CressmanActionPerformed

    private void jMenuItem_StreamlineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_StreamlineActionPerformed
        // TODO add your handling code here:
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        try {
            this.drawingPanel1.sample_Streamline();
        } catch (IOException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_jMenuItem_StreamlineActionPerformed

    private void jMenuItem_TestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_TestActionPerformed
        // TODO add your handling code here:
        this.drawingPanel1.clearObjects();
        File directory = new File(".");
        String fn = null;
        try {
            fn = directory.getCanonicalPath();
        } catch (IOException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        }
        fn = this.getClass().getResource("/sample/test2.grd").getPath();
        //fn = fn + File.separator + "sample" + File.separator + "test2.grd";
        File aFile = new File(fn);
        if (aFile.isFile()) {
            try {
                double[][] gridData = this.drawingPanel1.readSuferGridData(aFile);
                this.drawingPanel1.setGridData(gridData);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
            }

            double[] values = new double[]{20, 30, 40, 50, 60, 70, 80, 90};
            //double[] values = new double[]{70};
            this.drawingPanel1.setContourValues(values);
            this.drawingPanel1.tracingContourLines();
            this.drawingPanel1.smoothLines();
            this.drawingPanel1.getEcllipseClipping();
            this.drawingPanel1.clipLines();
            this.drawingPanel1.tracingPolygons();
            this.drawingPanel1.clipPolygons();

            this.drawingPanel1.setCoordinate();
            this.drawingPanel1.createLegend();
            this.repaint();
        }
    }//GEN-LAST:event_jMenuItem_TestActionPerformed

    private void jMenuItem_OutputDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_OutputDataActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            this.drawingPanel1.outputSurferGridData();
        } catch (IOException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMenuItem_OutputDataActionPerformed

    private void jMenuItem_AboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_AboutActionPerformed
        // TODO add your handling code here:
        frmAbout aboutDig = new frmAbout(this, false);
        aboutDig.setLocationRelativeTo(this);
        aboutDig.setVisible(true);
    }//GEN-LAST:event_jMenuItem_AboutActionPerformed

    private void jMenuItem_HelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_HelpActionPerformed
        // TODO add your handling code here:
        try {
            URI uri = new URI("http://www.meteothink.org/docs/wcontour/index.html");
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }
            if (desktop != null) {
                desktop.browse(uri);
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ioe) {
        }
    }//GEN-LAST:event_jMenuItem_HelpActionPerformed

    public DrawingPanel getDrawingPanel() {
        return this.drawingPanel1;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private DrawingPanel drawingPanel1;
    private javax.swing.JCheckBox jCheckBox_AntiAlias;
    private javax.swing.JCheckBox jCheckBox_BorderLine;
    private javax.swing.JCheckBox jCheckBox_Clipped;
    private javax.swing.JCheckBox jCheckBox_ContourLine;
    private javax.swing.JCheckBox jCheckBox_ContourPolygon;
    private javax.swing.JCheckBox jCheckBox_DiscreteData;
    private javax.swing.JCheckBox jCheckBox_GridData;
    private javax.swing.JCheckBox jCheckBox_Highlight;
    private javax.swing.JLabel jLabel_EndColor;
    private javax.swing.JLabel jLabel_StartColor;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem_About;
    private javax.swing.JMenuItem jMenuItem_Cressman;
    private javax.swing.JMenuItem jMenuItem_Help;
    private javax.swing.JMenuItem jMenuItem_IDW_Neighbour;
    private javax.swing.JMenuItem jMenuItem_IDW_Radius;
    private javax.swing.JMenuItem jMenuItem_OutputData;
    private javax.swing.JMenuItem jMenuItem_RandomData;
    private javax.swing.JMenuItem jMenuItem_Streamline;
    private javax.swing.JMenuItem jMenuItem_Test;
    private javax.swing.JMenu jMenu_Edit;
    private javax.swing.JMenu jMenu_Help;
    private javax.swing.JMenu jMenu_Interpolation;
    private javax.swing.JMenu jMenu_Sample;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTextField jTextField_Highlight;
    // End of variables declaration//GEN-END:variables
}
